#SCM=time petite -O3 --script
SCM=LTDL_LIBRARY_PATH=/opt/local/lib GUILE_LOAD_PATH=. GC_MAXIMUM_HEAP_SIZE=16000000000 time guile -s
#FC=mpif77 -Wall -g2 -fno-automatic -fopenmp -framework OpenCL
#FC=mpif77 -Wall -O6 -ffast-math -fno-automatic -framework OpenCL

FC=mpif77 -Wall -O6 -ffast-math -ffixed-line-length-none -fno-automatic -fopenmp -framework OpenCL

##FC=mpif77 -Wall -O2 -fno-automatic -fopenmp -framework OpenCL
##FC=mpif77 -Wall -fbounds-check -fno-automatic -fopenmp -framework OpenCL
##CC=gcc-mp-4.5 -fopenmp -O6 -ffast-math -Wall -framework OpenCL -fno-automatic

#OBJS=test.o
OBJS=test.o opencl_code.o

NP=8

MPIRUN=mpiexec -np ${NP}

run:	test
	CL_LOG_ERRORS=stdout GPU_DUMP_DEVICE_KERNEL=3 time ./test

runmpi:	test
	CL_LOG_ERRORS=stdout GPU_DUMP_DEVICE_KERNEL=3 time ${MPIRUN} ./test

str:	stream
	CL_LOG_ERRORS=stdout GPU_DUMP_DEVICE_KERNEL=3 time ./stream

str3d:	stream3d
	CL_LOG_ERRORS=stdout GPU_DUMP_DEVICE_KERNEL=3 time ./stream3d

strmpi:	stream
	CL_LOG_ERRORS=stdout GPU_DUMP_DEVICE_KERNEL=3 time ${MPIRUN} ./stream

str3dmpi:	stream3d
	CL_LOG_ERRORS=stdout GPU_DUMP_DEVICE_KERNEL=3 time ${MPIRUN} ./stream3d


test:   ${OBJS}
	${FC} ${OBJS} -o test

stream: stream.o
	${FC} stream.o -o stream

stream3d: stream3d.o
	${FC} stream3d.o -o stream3d

test.o:	test.f
	${FC} -c $< -o $@

opencl_code.o:	opencl_code.c
	${CC} -c $< -o $@

test.f: test.scm ./grid-gen/*.scm
	${SCM} test.scm

stream.f: stream.scm ./grid-gen/*.scm
	${SCM} stream.scm

stream3d.f: stream3d.scm ./grid-gen/*.scm
	${SCM} stream3d.scm

shock2:	shockROE
	time ./shockROE
	cat roe.dat | awk '{print $$1,$$2}' >roe_rho.dat
	cat roe.dat | awk '{print $$1,$$3}' >roe_p.dat
	cat roe.dat | awk '{print $$1,$$4}' >roe_u.dat
	xmgrace roe_rho.dat rho.dat
#	cat roe_rho.dat | awk '{print $$2}' | grep -- - ; true
#	cat roe_p.dat | awk '{print $$2}' | grep -- - ; true

shockROE.f: shock-ROE.scm grid-gen/*.scm
	${SCM} ./shock-ROE.scm

shockROE: shockROE.f
	${FC} shockROE.f -o shockROE

shock:	shocktube
	./shocktube
	xmgrace rho.dat p.dat v.dat

shocktube.f: shock-tube.scm grid-gen/*.scm
	${SCM} ./shock-tube.scm

shocktube: shocktube.f
	${FC} shocktube.f -o shocktube
